<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>阻止默认行为</title>
</head>
<body>
    <a href="http://baidu.com">百度</a>
    <script>
        let a = document.querySelector("a")
        a.onclick = function(e){
            //取消默认行为，比如超链接默认会跳转。
            e.preventDefault();
            console.log('哈哈哈！我是a标签');
            setTimeout(() => {
                location.href = "http://baidu.com"
            }, 5000);
        }

        //鼠标右键点击事件
        window.oncontextmenu = function(e){
            e.preventDefault()  //取消默认行为，鼠标右键后，不会出现菜单
            console.log('哈哈哈！右键点击事件');
        }
    </script>
</body>
</html>